package core.tool.httpconection;

import java.io.IOException;
import java.net.URLConnection;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.htmlparser.Parser;
import org.htmlparser.util.ParserException;

public class HttpConnectUtil {
	
	public static String getURLContent(String url) {
		String result="";
        HttpClient httpclient = new DefaultHttpClient();
        try {
            HttpGet httpget = new HttpGet(url);
            HttpResponse response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
            	result=EntityUtils.toString(entity);
            }
            httpget.abort();
        }catch (Exception e) {
        	e.printStackTrace();
        	result="";
        } 
        finally {
            httpclient.getConnectionManager().shutdown();
        }	
        return result;
	}
	
	public static void main(String[] args) throws ParserException, IOException {
  		String s=HttpConnectUtil.getURLContent("http://www.iteye.com/news");
  		System.out.println(s);
	}

	
}
